/**
 * @class   wosh::gui::KioskGadget
 * @brief   
 *
 *
 ****************************************************************************
 * @version $Id: KioskGadget.h 2258 2010-04-02 13:02:21Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Gui_KioskGadget_H__
 #define __WOSH_Gui_KioskGadget_H__

 #include <core/Object.h>

 #include <framework/gui/IWidget.h>
 #include <QtGui/QWidget>
 #include <QtGui/QGroupBox>
 #include <QtGui/QGraphicsWidget>
 #include <QtGui/QGraphicsProxyWidget>


namespace wosh {
 namespace gui {


class KioskGadget : public IWidget  {

	public:

		KioskGadget() : IWidget() {
			this->proxyItem = NULL;
		}
		virtual ~KioskGadget() { }

	public:
		virtual QGraphicsWidget* asQGraphicsWidget() {
			if ( this->proxyItem != NULL )
				return this->proxyItem;
			this->proxyItem = new QGraphicsProxyWidget();
			this->proxyItem->setWidget( this->asQWidget() );
			return this->proxyItem;
		 }

		virtual void setTitle( const QString& title ) = 0;
		virtual void setRefreshAuto( int seconds ) = 0;


	protected:
		QGraphicsProxyWidget* proxyItem;


}; // class def




class KioskGadgetProxy : public KioskGadget  {
	public:
		KioskGadgetProxy( QWidget* Item ) : KioskGadget() { 
			this->item = Item;
		}
		virtual ~KioskGadgetProxy() { }

	public:
		virtual QWidget* asQWidget() { return this->item; }

		virtual void busMessage( const Message&, const Bus* ) { }

		virtual void setTitle( const QString& ) { }
		virtual void setRefreshAuto( int ) { }


	protected:
		QWidget* item;

}; // class def


class KioskGadgetGeneric : public QGroupBox, public KioskGadget  {


	public:
		KioskGadgetGeneric() : QGroupBox(), KioskGadget() { 
			this->refreshTimer = 0;
		}
		virtual ~KioskGadgetGeneric() { }

	public:
		virtual QWidget* asQWidget() { return this; }

	public:

		virtual void setTitle( const QString& title ) {
			setWindowTitle(title);
			QGroupBox::setTitle(title);
		 }

		virtual void setRefreshAuto( int seconds ) {
			if ( this->refreshTimer != 0 ) {
				killTimer(this->refreshTimer);
				this->refreshTimer = 0;
			 }
			if ( seconds <= 0) return;
			this->refreshTimer = this->startTimer(seconds*1000);
		 }



	protected:
		void timerEvent( QTimerEvent* ) {
			if ( this->refreshTimer != 0 && isVisible() )
				refreshAll();
		 }

	protected:
		int refreshTimer;

}; // class def


  }; // namespace gui
}; // namespace wosh

#endif //__WOSH_Gui_Gadget_H__
